// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
    env: 'zbdc-6gavbhj633c62e27'
})
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
    console.log(event.type,event.reason)
    if (event.type == 'fail') {
        await db.collection('userUpfile') // 更新单词状态
            .where({
                content: event.currword
            })
            .update({
                data:{
                    status:event.type,
                    reason: event.reason
                }    
            })
    } else if (event.type == 'success') {
        await db.collection('CET4')
            .where({
                content: event.currword
            })
            .update({
                data: {
                    address: event.path,
                    lyric: event.lyric,
                    user: event.user
                }
            })
        await db.collection('CET6')
            .where({
                headWord: event.currword
            })
            .update({
                data: {
                    address: event.path,
                    lyric: event.lyric,
                    user: event.user
                }
            })
        await db.collection('KAOYAN')
            .where({
                headWord: event.currword
            })
            .update({
                data: {
                    address: event.path,
                    lyric: event.lyric,
                    user: event.user
                }
            })
        await db.collection('userUpfile') // 更新单词状态
            .where({
                content: event.currword
            })
            .update({
                data:{
                    address:"",
                    reason:"",
                    lyric:'',
                    status: event.type
                }  
            })
    }

}